feat: update UI to Include Game Title and Instructions#31
Conversation
… of assert_called_once_with
…decorator documentation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the typing application's user experience by adding automatic display of game title and instructions on startup, while also improving code quality through type annotation refactoring and documentation enhancements.
Key changes:
- Added
titleandinstructionsproperties that display automatically whenTypingGameis initialized - Refactored factory functions to use cleaner type annotation patterns, declaring types once before conditional blocks
- Enhanced
stopwatch_decowith overload signatures and comprehensive docstrings for better type safety and documentation
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_typing_game.py | Modified test assertions from assert_called_once_with to assert_called_with for system announcement verification |
| simple_typing_application/utils/stopwatch.py | Added @overload decorators and comprehensive docstrings to stopwatch_deco for improved type hints |
| simple_typing_application/ui/factory.py | Refactored type annotations to declare user_interface_config type once before conditional assignment |
| simple_typing_application/typing_game.py | Added title and instructions properties, displaying them on initialization; added blank announcement before typing targets |
| simple_typing_application/sentence_generator/openai_sentence_generator.py | Minor formatting change to comment placement in ainvoke call |
| simple_typing_application/sentence_generator/factory.py | Refactored type annotations to declare sentence_generator_config type once before conditional assignment |
| simple_typing_application/key_monitor/factory.py | Refactored type annotations to declare key_monitor_config type once before conditional assignment |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/test_typing_game.py
Outdated
|
|
||
| # assert | ||
| typing_game._ui.system_anounce.assert_called_once_with( # type: ignore # noqa | ||
| typing_game._ui.system_anounce.assert_called_with( # type: ignore # noqa |
There was a problem hiding this comment.
Changing from assert_called_once_with to assert_called_with weakens the test assertion. This test should verify that __skip_typing_step calls system_anounce exactly once with "SKIP!". The proper fix is to reset the mock before calling the method under test:
typing_game._ui.system_anounce.reset_mock() # Add this line
typing_game._TypingGame__skip_typing_step() # type: ignore
# assert
typing_game._ui.system_anounce.assert_called_once_with( # Keep the original assertion
"SKIP!",
color=typing_game._system_anounce_color,
)This ensures the test validates that the specific method only calls system_anounce once, regardless of earlier calls during initialization.
tests/test_typing_game.py
Outdated
|
|
||
| # assert | ||
| typing_game._ui.system_anounce.assert_called_once_with( # type: ignore # noqa | ||
| typing_game._ui.system_anounce.assert_called_with( # type: ignore # noqa |
There was a problem hiding this comment.
Changing from assert_called_once_with to assert_called_with weakens the test assertion. This test should verify that __done_typing_step calls system_anounce exactly once with "DONE!". The proper fix is to reset the mock before calling the method under test:
typing_game._ui.system_anounce.reset_mock() # Add this line
typing_game._TypingGame__done_typing_step() # type: ignore
# assert
typing_game._ui.system_anounce.assert_called_once_with( # Keep the original assertion
"DONE!",
color=typing_game._system_anounce_color,
)This ensures the test validates that the specific method only calls system_anounce once, regardless of earlier calls during initialization.
tests/test_typing_game.py
Outdated
|
|
||
| # assert | ||
| typing_game._ui.system_anounce.assert_called_once_with( # type: ignore | ||
| typing_game._ui.system_anounce.assert_called_with( # type: ignore |
There was a problem hiding this comment.
Changing from assert_called_once_with to assert_called_with weakens the test assertion. This test should verify that __exit_typing_step calls system_anounce exactly once with "EXIT!". The proper fix is to reset the mock before calling the method under test:
typing_game._ui.system_anounce.reset_mock() # Add this line
typing_game._TypingGame__exit_typing_step() # type: ignore
# assert
typing_game._ui.system_anounce.assert_called_once_with( # Keep the original assertion
"EXIT!",
color=typing_game._system_anounce_color,
)This ensures the test validates that the specific method only calls system_anounce once, regardless of earlier calls during initialization.
This pull request introduces several improvements and refactorings across the codebase, focusing on clarity, maintainability, and user experience. The most significant updates include adding a game title and instructions display, refactoring factory functions for cleaner type handling, enhancing the stopwatch utility with overloads and documentation, and refining UI feedback and test assertions.
User Experience Enhancements:
titleandinstructionsproperties inTypingGame, improving onboarding for users. (simple_typing_application/typing_game.py)simple_typing_application/typing_game.py)Code Quality and Maintainability:
create_key_monitor,create_sentence_generator,create_user_interface) to simplify type assignments and remove redundant type annotations, making the code cleaner and less error-prone. (simple_typing_application/key_monitor/factory.py,simple_typing_application/sentence_generator/factory.py,simple_typing_application/ui/factory.py) [1] [2] [3]stopwatch_decodecorator by adding overloads and comprehensive docstrings, clarifying its usage and enhancing type safety. (simple_typing_application/utils/stopwatch.py) [1] [2] [3]Testing and Logging Improvements:
assert_called_withinstead ofassert_called_once_withfor system announcements, allowing more flexible verification of UI feedback. (tests/test_typing_game.py) [1] [2] [3]simple_typing_application/sentence_generator/openai_sentence_generator.py,simple_typing_application/typing_game.py) [1] [2]These changes collectively improve the application's usability, code readability, and test reliability.